<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <?php require APP_PATH_WEB_ANLS.'Report/common/web_doc_meta.php';?>
    <title>分析列表</title>
	<?php require APP_PATH_WEB_ANLS.'Report/common/web_doc_link.php';?>
    <?php require APP_PATH_WEB_ANLS.'Report/common/web_doc_script.php';?>
	<style>
        #dataView {display: none; position: absolute;z-index:9999999;background-color: border: 1px solid #f9f9f9; background-color: white;
            padding: 5px;
           }
        .tr_bg_red { background-color: #c52d2d !important; color: white !important;}
    </style>

    <script type="text/javascript">

		var anlsData = null;
	
		function initAnlsData(){
			$.ajax({
				url:'/Anls/trade/getAnlsData'
				,dataType:'json'
				,success:function(data){
					if(!data) return false;
					anlsData = data;
					var tr = "";
					for(var code in data){
						if(!data[code])continue;
						var val = JSON.parse(data[code]);
						var winLose = val.winLose;
						var loseLimit = val.loseLimit;
						var highWinLt = val.highWinLt;
						var closeWinLt = val.closeWinLt;
						if(highWinLt.cur>8){
							tr += "<tr class='tr_bg_red'>";
						} else {
							tr += "<tr>";
						}
						tr += "<td code='"+code+"'>" + code + "</td>";
						tr += "<td>" + winLose.win + "</td>";
						tr += "<td>" + winLose.lose + "</td>";
						tr += "<td>" + winLose.profitPoint.toFixed(2) + "</td>";
						tr += "<td>" + winLose.profitPercent.toFixed(2) + "</td>";
						tr += "<td column='loseLimit'>" + loseLimit.cur + "</td>";
						
						tr += "<td column='highWinLt'>" + highWinLt.cur + "</td>";
						tr += "<td column='closeWinLt'>" + closeWinLt.cur + "</td>";
						tr += "</tr>";
					}
					$("#dataTable tbody").html(tr);
					initTrEvent();
				}
			});
		}

		function initTrEvent(){
			$("#dataTable tbody").find("tr").click(function(){
				var tr = $(this);
				var code = tr.find("td:eq(0)").html();
				$.ajax({
					url:'/Anls/trade/getTradeLog?code='+code
					,dataType:'json'
					,success:function(data){
						if(!data && !data.length) return false;
						var trs = "";
						for(var i=data.length-1;i>=0;i--){
							var log = JSON.parse(data[i]);
							if(log.bmhp<5){
								trs += "<tr class='tr_bg_red'>";
							} else {
								trs += "<tr>";
							}
							
							trs += "<td>"+log.buyOpenDate+"</td>";
							trs += "<td>"+log.buyCloseDate+"</td>";
							trs += "<td>"+log.buyOpenPrice+"</td>";
							trs += "<td>"+log.buyClosePrice+"</td>";
							trs += "<td>"+log.buyWinPoint+"</td>";
							trs += "<td>"+log.bwp+"%</td>";
							trs += "<td>"+log.buyMaxCloseProfit+"</td>";
							trs += "<td>"+log.bmcp+"%</td>";
							trs += "<td>"+log.buyMaxHighProfit+"</td>";
							trs += "<td>"+log.bmhp+"%</td>";
							trs += "<td>"+log.buyMaxCloseLoss+"</td>";
							trs += "<td>"+log.bmcl+"%</td>";
							trs += "<td>"+log.buyMaxHighLoss+"</td>";
							trs += "<td>"+log.bmhl+"%</td>";
							trs += "</tr>";
						}
						$("#tradeLogTable").find("tbody").html(trs);
						$("#tradeLogModal").find(".modal-title").html(code);
						var dv = $("#dataView");
						dv.hide();
						$("#tradeLogModal").modal('show');
					}
				});
			});
			$("#dataTable tbody").find("td").mouseover(function(){
				var column = $(this).attr("column");
				if(column){
					var _code = $(this).parent().find("td:eq(0)").attr("code");
					var vals = JSON.parse(anlsData[_code]);
					var dv = $("#dataView");
					dv.css("left",$(this).offset().left + 20 + "px");
					dv.css("top",$(this).offset().top + $(this).height() + 10 + "px");
					var html = column + "</br><table class='table table-bordered'>";
					for(var key in vals[column]){
						html += "<tr>";
						html += "<td>" + key + "</td><td>" + vals[column][key] + '</td>';
						html += "</tr>";
					}
					html += "</table>";
					dv.html(html);
					dv.show();
				}
			});
		}
    
		$(function(){
			initAnlsData();
		});
    </script>
  </head>

  <body>
	<div id="dataView" style="">
		123
	</div>
	<?php require APP_PATH_WEB_ANLS.'Report/common/nav.php';?>

    <div class="container-fluid">
      <div class="row">
        <?php require APP_PATH_WEB_ANLS.'Report/common/sidebar.php';?>
        
          <h2 class="sub-header">统计分析结果</h2>
          <div class="table-responsive">
            <table class="table table-striped" id="dataTable">
              <thead>
                <tr>
                  <th>品种</th>
                  <th>赢总数</th>
                  <th>输总数</th>
                  <th>总赢点数</th>
                  <th>总赢%</th>
                  <th>连输次数</th>
                  <th>最高赢利&lt;5%</th>
                  <th>平仓最大赢利&lt;0%</th>
                </tr>
              </thead>
              <tbody>
                                
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <div class="modal" tabindex="-1" role="dialog" id="tradeLogModal">
      <div class="modal-dialog" role="document" style="width:1200px;">
        <div class="modal-content">
        
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">Modal title</h4>
			</div>
			<div class="modal-body">
          
        		<table class="table table-striped table-bordered table-hover" id="tradeLogTable" >
        			<thead>
        				<tr>
                            <th style="width:100px;">开仓日期</th>
                            <th style="width:100px;">平仓日期</th>
                            <th style="width:80px;">开仓价</th>
                            <th style="width:80px;">平仓价</th>
                            
                            <th style="width:80px;">平仓盈利</th>
                            <th style="width:80px;">平仓盈利%</th>
                            <th style="width:80px;">平仓最大盈利</th>
                            <th style="width:80px;">平仓最大盈利%</th>
                            
                            <th style="width:80px;">最高盈利</th>
                            <th style="width:80px;">最高盈利%</th>
                            
                            <th style="width:80px;">平仓最大亏损</th>
                            <th style="width:80px;">平仓最大亏损%</th>
                            
                            <th style="width:80px;">最大亏损</th>
                            <th style="width:80px;">最大亏损%</th>
        				</tr>
        			</thead>
        			<tbody>
                                        
        			</tbody>
        		</table>
			</div>          
          
          
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    
    
  </body>
</html>
